<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据统计</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="../bower_components/morris.js/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="../bower_components/jvectormap/jquery-jvectormap.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="../bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="../bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <header class="main-header">
        <!-- Logo -->
        <a href="#" class="logo">
            <span class="logo-mini"><b>A</b>P</span>
            <span class="logo-lg"><b>Admin</b>Page</span>
        </a>
        <nav class="navbar navbar-static-top">
            <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>

            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <!-- Notifications: style can be found in dropdown.less -->
                    <li class="dropdown notifications-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <i class="fa fa-bell-o"></i>
                            <span class="label label-warning" id="warning"
                                  th:text="${session.warningMerches.size()}"></span>
                        </a>
                        <ul class="dropdown-menu ">
                            <li class="header" th:text="${session.warningMerches.size()}+'条商品库存数量达到警戒线'"></li>
                            <li>
                                <!-- inner menu: contains the actual data -->
                                <ul class="menu" th:each="m:${session.warningMerches}">
                                    <li>
                                        <a href="#">
                                            <i class="fa fa-warning text-yellow"></i>
                                            <span th:text="${m.getMerchName()}"></span>
                                        </a>
                                    </li>
                                </ul>
                            </li>
                            <li class="footer"><a href="#">View all</a></li>
                        </ul>
                    </li>

                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <span class="hidden-xs">Admin</span>
                        </a>
                    </li>
                </ul>
            </div>
        </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul class="sidebar-menu" data-widget="tree">
                <li class="header">MAIN NAVIGATION</li>
                <li>
                    <a href="/">
                        <i class="fa fa-pie-chart"></i> <span>数据统计</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="glyphicon glyphicon-gift"></i> <span>商品管理</span>
                        <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="/merch/listMerch"><i class="fa fa-circle-o"></i>商品列表</a></li>
                        <li><a href="/merch/addMerch"><i class="fa fa-circle-o"></i>添加商品</a></li>
                    </ul>
                </li>

                <li class="treeview">
                    <a href="#">
                        <i class="glyphicon glyphicon-send"></i>
                        <span>供应商管理</span>
                        <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="/provider/list"><i class="fa fa-circle-o"></i>供应商列表</a></li>
                        <li><a href="/provider/addProvider"><i class="fa fa-circle-o"></i>添加供应商</a></li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-laptop"></i>
                        <span>入库管理</span>
                        <span class="pull-right-container">
                            <i class="fa fa-angle-left pull-right"></i>
                        </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="/instock/list"><i class="fa fa-circle-o"></i>入库记录</a></li>
                        <li><a href="/instock/add"><i class="fa fa-circle-o"></i>添加记录</a></li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="glyphicon glyphicon-shopping-cart"></i> <span>销售管理</span>
                        <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="/sale/getAll"><i class="fa fa-circle-o"></i>订单列表</a></li>
                        <li><a href="/sale/adds"><i class="fa fa-circle-o"></i>添加订单</a></li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="glyphicon glyphicon-user"></i> <span>会员管理</span>
                        <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="/member/list"><i class="fa fa-circle-o"></i>会员列表</a></li>
                        <li><a href="/member/add"><i class="fa fa-circle-o"></i>添加会员</a></li>
                    </ul>
                </li>
                <li class="treeview active">
                    <a href="#">
                        <i class="fa fa-calendar"></i> <span>员工管理</span>
                        <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                    </a>
                    <ul class="treeview-menu">
                        <li class="active"><a href="/staff/listStaff"><i class="fa fa-circle-o"></i>员工列表</a></li>
                        <li><a href="/staff/addStaff"><i class="fa fa-circle-o"></i>添加员工</a></li>
                    </ul>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">

                    <!-- /.box -->
                    <!--/*@thymesVar id="name" type="java.lang.String"*/-->
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">库存商品：</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="StaffTable" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>员工id</th>
                                    <th>员工用户名</th>
                                    <th>员工姓名</th>
                                    <th>员工职位</th>
                                    <th>员工性别</th>
                                    <th>添加时间</th>
                                    <th>修改时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="s:${staffs}">
                                    <td th:text="${s.getStaffId()}"></td>
                                    <td th:text="${s.getStaffUsername()}"></td>
                                    <td th:text="${s.getStaffName()}"></td>
                                    <td th:text="${s.getStaffPosition()}"></td>
                                    <td th:text="${s.getStaffSex()}"></td>
                                    <td th:text="${s.getCreateTime()}"></td>
                                    <td th:text="${s.getUpdateTime()}"></td>
                                    <td>
                                        <button class="glyphicon glyphicon-pencil" data-toggle="modal"  th:data-whatever="${s.getStaffId()}" data-target="#updateModel"></button>
                                        <button class="glyphicon glyphicon-trash" data-toggle="modal"  th:data-whatever="${s.getStaffId()}" data-target="#deleteModel"></button>
                                    </td>
                                </tr>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <th>员工id</th>
                                    <th>员工用户名</th>
                                    <th>员工姓名</th>
                                    <th>员工职位</th>
                                    <th>员工性别</th>
                                    <th>添加时间</th>
                                    <th>修改时间</th>
                                    <th>操作</th>
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>






    <!-- /.content-wrapper -->

</div>
<!-- ./wrapper -->
<!--修改的模态框-->

<div aria-hidden="true" class="modal fade" id="updateModel" role="dialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
                <h4 class="modal-title" id="myModalLabel">更改员工</h4>
            </div>
            <div class="modal-body">
                <form action="javascript:void(0)" id="updateForm" role="form">
                    <div class="form-group">
                        <label for="updatestaffId">员工ID</label>
                        <input class="form-control" id="updatestaffId" name="staffId" type="text"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffName">员工姓名</label>
                        <input class="form-control" id="updatestaffName" name="staffName" type="text" />
                    </div>
                    <div class="form-group">
                        <label for="updatestaffPassword">员工密码</label>
                        <input class="form-control" id="updatestaffPassword" name="staffPassword" type="text"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffSex">员工性别</label>
                        <input class="form-control" id="updatestaffSex" name="staffSex"  type="text" value="1000"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffPosition">员工职位</label>
                        <input class="form-control" id="updatestaffPosition" name="staffPosition" type="text"  value="1"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffUsername">员工用户名</label>
                        <input class="form-control" id="updatestaffUsername" name="staffUsername" placeholder="请输入员工用户名" type="text"/>
                    </div>

                </form>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" type="button">取消</button>
                    <button class="btn btn-primary" id="updateStaff" type="button">修改</button>
                </div>
            </div>
        </div>
    </div>
</div>


<div aria-hidden="true" class="modal fade" id="deleteModel" role="dialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
                <h4 class="modal-title" id="myModalLabel2">删除商品</h4>
            </div>
            <div class="modal-body">
                <form action="javascript:void(0)" id="deleteFrom" role="form">
                    <div class="form-group">
                        <label for="updatestaffId2">员工ID</label>
                        <input class="form-control" id="updatestaffId2" name="staffId" readonly type="text"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffName2">员工姓名</label>
                        <input class="form-control" id="updatestaffName2" name="staffName" readonly type="text" />
                    </div>
                    <div class="form-group">
                        <label for="updatestaffPassword2">员工密码</label>
                        <input class="form-control" id="updatestaffPassword2" name="staffPassword" readonly type="text"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffSex2">员工性别</label>
                        <input class="form-control" id="updatestaffSex2" name="staffSex"  readonly type="text" value="1000"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffPosition2">员工职位</label>
                        <input class="form-control" id="updatestaffPosition2" name="staffPosition" readonly type="text"  value="1"/>
                    </div>
                    <div class="form-group">
                        <label for="updatestaffUsername2">员工用户名</label>
                        <input class="form-control" id="updatestaffUsername2" name="staffUsername" placeholder="请输入员工用户名" readonly type="text"/>
                    </div>

                </form>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" type="button">取消</button>
                    <button class="btn btn-danger" id="deleteStaff"  type="button">删除</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- jQuery 3 -->
<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="../../bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../../bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="../../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- page script -->
<script>
    $(document).ready(function () {
        $('#updateModel').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // 触发事件的按钮
            var id = button.data('whatever');// 解析出data-whatever内容
            var modal = $(this);
            $.ajax({
                url:"/staff/getStaffByid/"+id,
                type: "get",
                dataType: "json",
                success: function (date) {
                    modal.find('#updatestaffId').val(date.staffId);
                    modal.find('#updatestaffUsername').val(date.staffUsername);
                    modal.find('#updatestaffPassword').val(date.staffPassword);
                    modal.find('#updatestaffName').val(date.staffName);
                    modal.find('#updatestaffSex').val(date.staffSex);
                    modal.find('#updatestaffPosition').val(date.staffPosition);
                }
            })
        })

        $('#deleteModel').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // 触发事件的按钮
            var id = button.data('whatever');// 解析出data-whatever内容
            var modal = $(this);
            $.ajax({
                url:"/staff/getStaffByid/"+id,
                type: "get",
                dataType: "json",
                success: function (date) {
                    modal.find('#updatestaffId2').val(date.staffId);
                    modal.find('#updatestaffUsername2').val(date.staffUsername);
                    modal.find('#updatestaffPassword2').val(date.staffPassword);
                    modal.find('#updatestaffName2').val(date.staffName);
                    modal.find('#updatestaffSex2').val(date.staffSex);
                    modal.find('#updatestaffPosition2').val(date.staffPosition);
                }
            })
        })

        var table = $('#StaffTable').DataTable({
            'paging': true,
            'lengthChange': true,
            'searching': true,
            'ordering': true,
            'info': true,
            'autoWidth': true
        });





        $('#updateStaff').click(function () {
            var msg = "你确定要修改吗";
            if (confirm(msg) == true){
                var updateData = $("#updateForm").serializeArray();
                var data = "{";
                for (var i = 0; i < updateData.length; i++) {
                    var name = updateData[i].name;
                    var value = updateData[i].value;
                    data = data + "\"" + name + "\":\"" + value.trim() + "\",";
                }
                data = data.substring(0, data.length - 1);
                data = data + "}";
                console.log(data);
                $.ajax({
                    url: "/staff/update",
                    contentType: 'application/json',
                    dataType: "json",
                    type: "post",
                    data: data,
                    success: function (status) {
                        if (status.code == 1) {
                            $('#updateModal').modal('hide');
                            alert("update success");
                            window.location.reload();
                        } else {
                            alert("update failed");
                        }
                    },
                    error: function (data) {
                        $('#updateModal').modal('hide');
                        alert("update ok");
                        window.location.reload();
                    }
                });

            }
        });


        $('#deleteStaff').click(function () {
            var msg = "你确定要删除选中数据吗";
            if (confirm(msg) == true) {
                var id=$("#updatestaffId2").val();
                $.ajax({
                    url: "/staff/delete/" + id,
                    type: "get",
                    success: function (data) {
                        if (data.code == 1)
                            alert(data.msg);
                        else
                            alert(data.msg);
                        window.location.reload();
                    },
                    error: function (data) {
                        alert("error");
                        window.location.reload();
                    }
                });
                location.reload();
            }
        })
    })


</script>
</body>
</html>
